package com.accompany.controller;

import com.accompany.common.Result;
import com.accompany.entity.SkillTag;
import com.accompany.service.SkillTagService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 技能标签表 前端控制器
 * </p>
 *
 * @author DC
 * @since 2024-12-26
 */
@RestController
@RequestMapping("/skill-tag")
@Tag(name = "SkillTagController", description = "技能标签管理")
public class SkillTagController {

    @Autowired
    private SkillTagService skillTagService;

    /**
     * 创建技能标签
     *
     * @param skillTag 技能标签信息
     * @return Result对象，包含操作结果
     */
    @PostMapping("/create")
    @Operation(summary = "创建技能标签", description = "创建一个新的技能标签")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "技能标签创建成功"),
            @ApiResponse(responseCode = "400", description = "请求参数不正确")
    })
    public Result<?> createSkillTag(@RequestBody SkillTag skillTag) {
        skillTagService.createSkillTag(skillTag);
        return Result.success();
    }

    /**
     * 删除技能标签
     *
     * @param id 技能标签ID
     * @return Result对象，包含操作结果
     */
    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除技能标签", description = "根据技能标签ID删除技能标签")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "技能标签删除成功"),
            @ApiResponse(responseCode = "404", description = "技能标签不存在")
    })
    public Result<?> deleteSkillTag(@PathVariable Long id) {
        skillTagService.deleteSkillTag(id);
        return Result.success("删除成功");
    }

    /**
     * 更新技能标签信息
     *
     * @param skillTag 技能标签信息
     * @return Result对象，包含操作结果
     */
    @PutMapping("/update")
    @Operation(summary = "更新技能标签信息", description = "根据技能标签ID更新技能标签信息")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "技能标签信息更新成功"),
            @ApiResponse(responseCode = "404", description = "技能标签不存在")
    })
    public Result<?> updateSkillTag(@RequestBody SkillTag skillTag) {
        skillTagService.updateSkillTag(skillTag);
        return Result.success("更新成功");
    }

    /**
     * 获取单个技能标签信息
     *
     * @param id 技能标签ID
     * @return Result对象，包含技能标签信息
     */
    @GetMapping("/{id}")
    @Operation(summary = "获取单个技能标签信息", description = "根据技能标签ID获取技能标签信息")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "获取成功"),
            @ApiResponse(responseCode = "404", description = "技能标签不存在")
    })
    public Result<SkillTag> getSkillTagById(@PathVariable Long id) {
        SkillTag skillTag = skillTagService.getSkillTagById(id);
        return Result.success(skillTag);
    }

    /**
     * 获取所有技能标签列表
     *
     * @return Result对象，包含技能标签列表
     */
    @GetMapping
    @Operation(summary = "获取所有技能标签列表", description = "获取所有技能标签的列表")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "获取成功"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    public Result<List<SkillTag>> getAllSkillTags() {
        List<SkillTag> skillTags = skillTagService.getAllSkillTags();
        return Result.success(skillTags);
    }

    /**
     * 分页查询技能标签列表
     *
     * @param page  页码
     * @param size  每页大小
     * @return Result对象，包含分页后的技能标签列表
     */
    @GetMapping("/page")
    @Operation(summary = "分页查询技能标签列表", description = "根据页码和每页大小分页查询技能标签列表")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "分页查询成功"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    public Result<Page<SkillTag>> getPaginatedSkillTags(
            @Parameter(description = "页码", required = true) @RequestParam(name = "page", defaultValue = "1") Integer page,
            @Parameter(description = "每页大小", required = true) @RequestParam(name = "size", defaultValue = "10") Integer size) {
        Page<SkillTag> pageResult = skillTagService.getPaginatedSkillTags(page, size);
        return Result.success(pageResult);
    }
}